import 'package:flutter/material.dart';
import 'package:flutter_demo/pages/page_with_title.dart';
import 'package:flutter_demo/widgets/app_widgets.dart';

class OpacityPage extends PageWithTitle {
  const OpacityPage() : super("透明度组件(Opacity)");

  @override
  List<Widget> buildContentWidgets(BuildContext context) {
    return const [
      PrimaryTitle("简介"),
      BodyText("透明度组件直接通过RenderObject.updateCompositedLayer来修改图层透明度设"
          "置，使得自身包括子渲染对象的绘制内容受到透明度影响"),
      AppSpacer.large,
      _Example(),
      AppSpacer.mini,
      UlItem("Opacity"),
      LabelText("- opacity，透明度设置，范围[0,1]"),
    ];
  }
}

class _Example extends StatelessWidget {
  const _Example();

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      shrinkWrap: true,
      itemCount: 5,
      itemBuilder: (context, index) {
        return Opacity(
          opacity: (index+1) / 5.0,
          child: Container(
            color: Theme.of(context).colorScheme.primary,
            child: Text(
              "Primary Widget",
              style: Theme.of(context)
                  .textTheme
                  .bodyLarge
                  ?.copyWith(color: Theme.of(context).colorScheme.onPrimary),
            ),
          ),
        );
      },
    );
  }
}
